using System;
using System.Collections.Generic;
using System.IO;

namespace O3LEngine
{
	/// <summary>
	/// This class reads in txt files with key value pairs
	/// </summary>
	public class PropReader
	{
		Dictionary<string,string> m_List;

		
		public PropReader(string file)
		{
			FileStream readFile;
			readFile = File.OpenRead(file);
			
			char[] seperators = new char[] { '=', ':', ' ', '\t' };
			m_List = new Dictionary<string,string>();

			StreamReader reader = new StreamReader(readFile);
			string szLine;
			while ((szLine = reader.ReadLine()) != null) {
				string[] strings = szLine.Split(seperators, StringSplitOptions.RemoveEmptyEntries);

				//If the entry is empty or one word or it has more than 4 ignore it
				if (strings.Length != 2)
					continue;
				//if it starts with // then it is a comment
				if (strings[0].StartsWith("//"))
					continue;

				m_List.Add(strings[0],strings[1]);

			}
			reader.Close();
			readFile.Close();
		}
		public void getValue(string key,ref string value)
		{
			m_List.TryGetValue(key,out value);
		}

	}
}
